const path = require("path");
const rootPath = require("../../root");
const fs = require("fs");
const { outpath } = require("../../config.json");
// 写入样式
function wr(opath, dpath, flag = "w") {
	try {
		let data = fs.readFileSync(path.join(rootPath, opath), {
			encoding: "utf-8",
		});

		data = " <style>" + data + "</style>";

		fs.writeFileSync(dpath, data, {
			encoding: "utf-8",
			flag,
		});
	} catch (_) {
		console.log(_);
	}
}
function writeStyle(style, modpath, themepaht, filename) {
	const keys = Object.keys(style);
	for (key of keys) {
		const sNode = style[key];
		// 写入样式
		if (sNode.stylepath) {
			wr(path.join(modpath, sNode.stylepath), path.join(outpath, filename), "a");
		}
		// 写入主题
		if (sNode.theme) {
			wr(path.join(themepaht, sNode.theme), path.join(outpath, filename), "a");
		}
	}
}
module.exports = writeStyle;
